package tech.lq0.dreamaticdelight.datagen;

import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.model.generators.ItemModelBuilder;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import tech.lq0.dreamaticdelight.ModUtils;
import tech.lq0.dreamaticdelight.init.DMDItems;

@SuppressWarnings({"ConstantConditions", "UnusedReturnValue", "SameParameterValue", "unused"})
public class ModItemModelProvider extends ItemModelProvider {

    public ModItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
        super(output, ModUtils.MOD_ID, existingFileHelper);
    }

    @Override
    protected void registerModels() {
        handheldItem(DMDItems.FUKAMIZU_BREAD_KNIFE);

        simpleItem(DMDItems.MOMO_SAUCE);
        simpleItem(DMDItems.FUKAMIZU_BREAD_SLICE);
        simpleItem(DMDItems.PLUM_BREAD_SLICE);
        simpleItem(DMDItems.FUKAMIZU_PLUM_SAUCE);
        simpleItem(DMDItems.FUKAMIZU_FISH_SLICE);
        simpleItem(DMDItems.COOKED_FUKAMIZU_FISH_SLICE);
        simpleItem(DMDItems.UNI_MILLET_OIL);
        simpleItem(DMDItems.CARNIVAL_MEAL);
        simpleItem(DMDItems.DARK_BONE_BROTH);
        simpleItem(DMDItems.MEIYA_CAKE);
        simpleItem(DMDItems.MOMO_SANDWICH);
        simpleItem(DMDItems.PLUM_SANDWICH);
        simpleItem(DMDItems.FUKAMIZU_FISH_SANDWICH);
        simpleItem(DMDItems.VANILLA_FUKAMIZU_COOKIE);
        simpleItem(DMDItems.COCOA_FUKAMIZU_COOKIE);
        simpleItem(DMDItems.MOCHA_FUKAMIZU_COOKIE);
        simpleItem(DMDItems.CHOCOLATE_FUKAMIZU_COOKIE);
        simpleItem(DMDItems.CHIRAM_UMBRA);
        simpleItem(DMDItems.CHIRAM_PENUMBRA);
    }

    private ItemModelBuilder simpleItem(RegistryObject<Item> item) {
        return withExistingParent(item.getId().getPath(), new ResourceLocation("item/generated"))
                .texture("layer0", ModUtils.loc("item/" + item.getId().getPath()));
    }

    private ItemModelBuilder simpleItem(RegistryObject<Item> item, String renderType) {
        return simpleItem(item).renderType(renderType);
    }

    private ItemModelBuilder simpleItem(ResourceLocation item) {
        return withExistingParent(item.getPath(), new ResourceLocation("item/generated"))
                .texture("layer0", ModUtils.loc("item/" + item.getPath()));
    }

    public void evenSimplerBlockItem(RegistryObject<Block> block) {
        this.withExistingParent(ModUtils.MOD_ID + ":" + ForgeRegistries.BLOCKS.getKey(block.get()).getPath(),
                modLoc("block/" + ForgeRegistries.BLOCKS.getKey(block.get()).getPath()));
    }

    private ItemModelBuilder handheldItem(RegistryObject<Item> item) {
        return withExistingParent(item.getId().getPath(), new ResourceLocation("item/handheld"))
                .texture("layer0", ModUtils.loc("item/" + item.getId().getPath()));
    }

}